﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TimeToGo.Presentation.ViewModels;
using TimeToGo.Repositories;

namespace TimeToGo.Presentation.Views
{
    /// <summary>
    /// Interaction logic for TimesVeiw.xaml
    /// </summary>
    public partial class TimesVeiw : Window, ITimesView
    {
        private TimesViewModel _vm;

        public TimesVeiw()
        {
            InitializeComponent();
            _vm = new TimesViewModel(this, new TimeInfoRepository());
            DataContext = _vm;
        }

        public TimeInfo SelectedTime
        {
            get { return TimesListView.SelectedItem as TimeInfo; }
        }

        private void TimesListView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && SelectedTime != null)
            {
                _vm.ModifyTime(SelectedTime);
            }
        }

        private void TimesListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (SelectedTime != null)
            {
                _vm.ModifyTime(SelectedTime);
            }
        }
    }
}
